package com.example.mydy.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesManager {
    private static final String PREF_NAME = "MydyPrefs";
    private static final String KEY_IS_LOGGED_IN = "is_logged_in";
    private static final String KEY_USERNAME = "username";
    private static final String KEY_NICKNAME = "nickname";
    private static final String KEY_IS_ADMIN = "is_admin";

    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }

    public static void setLoggedIn(Context context, boolean isLoggedIn) {
        getSharedPreferences(context).edit().putBoolean(KEY_IS_LOGGED_IN, isLoggedIn).apply();
    }

    public static boolean isLoggedIn(Context context) {
        return getSharedPreferences(context).getBoolean(KEY_IS_LOGGED_IN, false);
    }

    public static void setUsername(Context context, String username) {
        getSharedPreferences(context).edit().putString(KEY_USERNAME, username).apply();
    }

    public static String getUsername(Context context) {
        return getSharedPreferences(context).getString(KEY_USERNAME, "");
    }

    public static void setNickname(Context context, String nickname) {
        getSharedPreferences(context).edit().putString(KEY_NICKNAME, nickname).apply();
    }

    public static String getNickname(Context context) {
        return getSharedPreferences(context).getString(KEY_NICKNAME, "");
    }

    public static void setAdmin(Context context, boolean isAdmin) {
        getSharedPreferences(context).edit().putBoolean(KEY_IS_ADMIN, isAdmin).apply();
    }

    public static boolean isAdmin(Context context) {
        return getSharedPreferences(context).getBoolean(KEY_IS_ADMIN, false);
    }

    public static void clearLoginInfo(Context context) {
        getSharedPreferences(context).edit()
                .remove(KEY_IS_LOGGED_IN)
                .remove(KEY_USERNAME)
                .remove(KEY_NICKNAME)
                .remove(KEY_IS_ADMIN)
                .apply();
    }
} 